package com.yang.booking.controller;

import com.yang.booking.pojo.TimePoint;
import com.yang.booking.service.ShiftManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ShiftManagementController {

    @Autowired
    private ShiftManagementService shiftManagementService;

    @PostMapping("/provider/shiftManagement/queryShiftManagementAll")
    public Map<String, Object> queryShiftManagementAll(@RequestParam(name = "storeId") String storeId
    ){
        return shiftManagementService.queryShiftManagementAll(storeId);
    }

    @PostMapping("/provider/shiftManagement/insertShiftManagement")
    public Map<String, Object> insertShiftManagement(@RequestParam(name = "storeId") String storeId,
                                                    @RequestParam(name = "name") String name,
                                                    @RequestParam(name = "shiftTimeList") String shiftTimeList
    ){
        return shiftManagementService.insertShiftManagement(storeId, name, shiftTimeList);
    }

    @PostMapping("/provider/shiftManagement/updateShiftManagement")
    public Map<String, Object> updateShiftManagement(@RequestParam(name = "shiftManagementId") String shiftManagementId,
                                                     @RequestParam(name = "name") String name,
                                                     @RequestParam(name = "shiftTimeList") String shiftTimeList
    ){
        return shiftManagementService.updateShiftManagement(shiftManagementId, name, shiftTimeList);
    }

    @PostMapping("/provider/shiftManagement/queryStaffShift")
    public Map<String, Object> queryStaffShift(@RequestParam(name = "storeId") String storeId,
                                                @RequestParam(name = "staffId") String staffId,
                                                @RequestParam(name = "nowDate") String nowDate,
                                               @RequestParam(name = "call") String call,
                                               @RequestParam(name = "startOrEnd") String startOrEnd
    ) throws ParseException {

        List<String> staffShiftTimeList = shiftManagementService.queryStaffShift(storeId, staffId, nowDate, call, startOrEnd);

        Map<String, Object> msg = new HashMap<String, Object>();
        msg.put("massage", "查询成功");
        msg.put("code", 200);
        Map<String, Object> data = new HashMap<String, Object>();
        msg.put("data", data);
        data.put("rows", staffShiftTimeList);
        data.put("total", staffShiftTimeList.size());

        return msg;
    }

    @PostMapping("/provider/shiftManagement/queryWebStaffShift")
    public Map<String, Object> queryWebStaffShift(@RequestParam(name = "storeId") String storeId,
                                               @RequestParam(name = "staffId") String staffId,
                                               @RequestParam(name = "nowDate") String nowDate,
                                               @RequestParam(name = "startOrEnd") String startOrEnd
    ) throws ParseException {

        List<TimePoint> staffShiftTimeList = shiftManagementService.queryWebStaffShift(storeId, staffId, nowDate, startOrEnd);

        Map<String, Object> msg = new HashMap<String, Object>();
        msg.put("massage", "查询成功");
        msg.put("code", 200);
        Map<String, Object> data = new HashMap<String, Object>();
        msg.put("data", data);
        data.put("rows", staffShiftTimeList);
        data.put("total", staffShiftTimeList.size());

        return msg;
    }

    @PostMapping("/provider/shiftManagement/queryAppletsStaffShift")
    public Map<String, Object> queryAppletsStaffShift(@RequestParam(name = "storeId") String storeId,
                                                  @RequestParam(name = "staffId") String staffId,
                                                  @RequestParam(name = "nowDate") String nowDate,
                                                      @RequestParam(name = "call") String call
    ) throws ParseException {

        Map<String, List<TimePoint>> staffShiftTimeList = shiftManagementService.queryAppletsStaffShift(storeId, staffId, nowDate, call);

        Map<String, Object> msg = new HashMap<String, Object>();
        msg.put("massage", "查询成功");
        msg.put("code", 200);
        Map<String, Object> data = new HashMap<String, Object>();
        msg.put("data", data);
        data.put("rows", staffShiftTimeList);
        data.put("total", staffShiftTimeList.size());

        return msg;
    }

    @PostMapping("/provider/shiftManagement/querySelectManagement")
    public Map<String, Object> querySelectManagement(@RequestParam(name = "storeId") String storeId
    ){
        return shiftManagementService.querySelectManagement(storeId);
    }
}
